<?php
require '../dao/Db.class.php';
require '../dao/Result.class.php';
function query($t, $table){
  $result = array();

  $db = Db::getInstance();
  try{
    $con = $db->connect();
    $query = mysql_query("SELECT keyword, location FROM ".$table." where keyword like '%".$t."%'");
    if($query){
      while($row = mysql_fetch_array($query)){
        $queryText = array();
        $queryText[$t] = null;
        $result[$row['keyword']] = new Result($row['location'], $queryText, ((double)strlen($t) / strlen($row['keyword'])));
      }
    }
    // mysql_close($con);
    return $result;
  }catch(Exception $e){
      echo "sorry,error was happend.".$e->getMessage();
  }
}

function add($keyword, $location){
  $db = Db::getInstance();
  $con = $db->connect();
  $query = mysql_query("INSERT INTO location (keyword, location) VALUES ('".$keyword."', '".$location."')");
  return $query;
}
 ?>
